package com.woohua.thread.wait;

/***
 * @title WaiteDemo3
 * @description
 * @author woo hua
 * @version 1.0.0
 * @create 2023/3/9 11:11
 **/
public class WaiteDemo2 {

    public static void main(String[] args) {
        // 初始化任务队列
        TaskQueue taskQueue = new TaskQueue();

        // 启动任务 consumer
        for (int i = 0; i < 2; i++) {
            new Thread(new Consumer(taskQueue)).start();
        }

        // 休眠一段时间，等到consumer都启动好
        sleep(2000);


        // 启动任务生产者 producer
        new Thread(new Producer(taskQueue)).start();
    }

    private static void sleep(long millis) {
        System.out.println("WaiteDemo2 sleep");
        try {
            Thread.sleep(millis);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
